package com.example.job_backend.controller;

import com.example.job_backend.model.Position;
import com.example.job_backend.model.PushPosition;
import com.example.job_backend.model.R;
import com.example.job_backend.service.PushPositionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class PushPositionController {
    @Resource
    private PushPositionService pushPositionService;

    @GetMapping("/recommendPosition")
    public R recommendPosition(String positionId, @RequestParam("students") String studentsStr, String publisherId) {
        String[] students = studentsStr.replaceAll("[^\\d,]", "").split(",");
        for (String student : students) {
            System.out.println(student);
            PushPosition pushPosition = new PushPosition();
            pushPosition.setPositionId(positionId);
            pushPosition.setStudentId(student);
            pushPosition.setPublisherId(publisherId);
            pushPositionService.save(pushPosition);
        }
        return new R(200, "请求成功", null);
    }

    @GetMapping("/getPositionByUsername")
    public R getPositionByUsername(String currentUsername) {
        List<Position> list = pushPositionService.getPositionByUsername(currentUsername);
        return new R(200, "请求成功", list);
    }
}
